// pages/userInfo/index.js
const app = getApp()
const { $Message } = require('../../components/dist/base/index');
Page({
  data: {
    userInfo:'',
    setIdenShow:false,
    input:''
  },
  onLoad: function (options) {
    this.setData({
      isLogin:app.globalData.isLogin,
      userInfo:app.globalData.userInfo
    })
  },
  onReady: function () {

  },
  onShow: function () {
    this.setData({
      isLogin:app.globalData.isLogin,
      userInfo:app.globalData.userInfo
    })
  },
  getUserProfile(){
    const that = this
    app.getUserProfile().then(res =>{
      that.setData({
      isLogin:app.globalData.isLogin,
      userInfo:app.globalData.userInfo
      })
    })
  },
  handleIdenSubmit() {
    const that = this
    const db = wx.cloud.database()
    if(this.data.input==''){
      $Message({
        content: '请输入内容！',
        type: 'warning'
    })
    }
    else{
      // console.log(11)
      db.collection('user').doc(app.globalData.userInfo._id).update({
        data:{
          identity:that.data.input
        },
        success(res){
          // console.log(res)
          db.collection('user').doc(app.globalData.userInfo._id).get({
            success(res){
              // console.log(res)
              that.setData({
                userInfo:res.data
              })
              app.globalData.userInfo = res.data
            }
          })
          that.setData({
            setIdenShow: false,
            input:''
          })
        }
      })
    }

  },
  handleIdenClose() {
    this.setData({
      setIdenShow: false
    })
  },
  handleIdenOpen(){
    this.setData({
      setIdenShow: true
    })
  },
  changeIdenValue(e){
    this.setData({
      input:e.detail.value
    })
  }
})